package com.ljd.music.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/***
 * 定位各种文件和头像地址的配置
 */
@Configuration
public class FileConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         *      addResourceHandler: 当请求为指定路径时
         *      addResourceLocations: 跳转到指定路径
         *          System.getProperty("user.dir"): 项目所在目录,包含项目: D:\music
         *          System.getProperty("file.separator"): 分隔符,用于在不同的操作系统环境下使用不同的分割符
         */

        // 歌手图像
        registry.addResourceHandler("/images/singerPic/**").addResourceLocations(
                "file:" + System.getProperty("user.dir") + System.getProperty("file.separator")+ "images"
                +System.getProperty("file.separator") + "singerPic" + System.getProperty("file.separator")
        );

        // 用户图像
        registry.addResourceHandler("/images/consumerPic/**").addResourceLocations(
                "file:" + System.getProperty("user.dir") + System.getProperty("file.separator")+ "images"
                        +System.getProperty("file.separator") + "consumerPic" + System.getProperty("file.separator")
        );

        // 歌单图片
        registry.addResourceHandler("/images/songListPic/**").addResourceLocations(
                "file:" + System.getProperty("user.dir") + System.getProperty("file.separator")+ "images"
                        +System.getProperty("file.separator") + "songListPic" + System.getProperty("file.separator")
        );

        // 歌曲图片
        registry.addResourceHandler("/images/songPic/**").addResourceLocations(
                "file:" + System.getProperty("user.dir") + System.getProperty("file.separator")+ "images"
                        +System.getProperty("file.separator") + "songPic" + System.getProperty("file.separator")
        );

        // 歌曲
        registry.addResourceHandler("/song/**").addResourceLocations(
                "file:" + System.getProperty("user.dir") + System.getProperty("file.separator")+ "song"
                        +System.getProperty("file.separator")
        );
    }
}
